package fr.louloutes.lolshooter;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

/**
 * @author Louloute Menu Activity - S'active automatiquement après le splash
 *         screen - Propose au joueur de - lancer le jeu - afficher les scores -
 *         afficher un écran d'aide - afficher l'écran des settings
 */
public class MenuAct extends LOLActivity
{
	/** Called when the activity is first created. */
	@Override
	public void onCreate( Bundle savedInstanceState )
	{
		Utils.Log( "Menu onCreate", this );
		super.onCreate( savedInstanceState );
		setContentView( R.layout.menu );

		// Tests avec un VideoView
		/*		VideoView myVid = ( VideoView ) findViewById( R.id.video_ferme );
				MediaController mediaController = new MediaController( this );
				mediaController.setAnchorView( myVid );
				myVid.setMediaController( mediaController );
				Uri path = Uri.parse( "android.resource://" + getPackageName()
						+ "/raw/laferme" );
				myVid.setVideoURI( path );
				myVid.requestFocus();
				myVid.start();
		*/

		/* Essais de log -> je te laisse choisir la façon dont on va logger.
		 * Perso, ta classe me plaît bien car on peut faire du simple et du plus complexe.
		 * Si ça te va, je te laisse retirer ma classe Utils et modifier dans tous les .java
		 * les "Utils.Log(...)" par des "LolLog.rv(...)" ou ce qu'il faut
		 * 
		 *  Ah oui, comme je te l'ai dit, l'utilisation du subLogger génère plein de logs "parasite", cf le log filtré
		 */
		/*Utils.Log( "TEEEST Log Menu via Utils", this );

		LolLog.rv( "TEEEST Log Menu via LolLog simple" );
		LolLog myLolLog = LolLog.getRoot().getSubLogger(
				"TEEEST Log Menu via LolLog tag interm" );
		myLolLog.wtf( "tag final" );
		*/
		// createListeners();

		ListView menuList = ( ListView ) findViewById( R.id.menu_list );
		String[] menuItems = { getResources().getString( R.string.menu_play ),
				getResources().getString( R.string.menu_scores ),
				getResources().getString( R.string.menu_settings ),
				getResources().getString( R.string.menu_help ) };
		ArrayAdapter<String> adapt = new ArrayAdapter<String>( this,
				R.layout.menu_item, menuItems );
		menuList.setAdapter( adapt );

		menuList.setOnItemClickListener( new AdapterView.OnItemClickListener()
		{
			@Override
			public void onItemClick( AdapterView<?> parent, View itemClicked,
					int position, long id )
			{
				TextView textView = ( TextView ) itemClicked;
				String strText = textView.getText().toString();
				if ( strText.equalsIgnoreCase( getResources().getString(
						R.string.menu_play ) ) )
				{
					// Lancer GameAct
					startActivity( new Intent( MenuAct.this, GameAct.class ) );
				} else if ( strText.equalsIgnoreCase( getResources().getString(
						R.string.menu_help ) ) )
				{
					// Lancer HelpAct
					startActivity( new Intent( MenuAct.this, HelpAct.class ) );
				} else if ( strText.equalsIgnoreCase( getResources().getString(
						R.string.menu_settings ) ) )
				{
					// Launch the Settings Activity
					startActivity( new Intent( MenuAct.this, SettingsAct.class ) );
				} else if ( strText.equalsIgnoreCase( getResources().getString(
						R.string.menu_scores ) ) )
				{
					// Launch the Scores Activity
					startActivity( new Intent( MenuAct.this, ScoresAct.class ) );
				}
			}
		} );

	}

	/*
		private void createListeners()
		{
			Utils.Log( "Creating listeners", this );
			Button game = ( Button ) findViewById( R.id.menu_play_button );
			Button scores = ( Button ) findViewById( R.id.menu_scores_button );
			Button settings = ( Button ) findViewById( R.id.menu_settings_button );
			Button help = ( Button ) findViewById( R.id.menu_help_button );

			game.setOnClickListener( getBasicLauncherListener( GameAct.class ) );
			scores.setOnClickListener( getBasicLauncherListener( ScoresAct.class ) );
			settings.setOnClickListener( getBasicLauncherListener(
			SettingsAct.class ) );
			help.setOnClickListener( getBasicLauncherListener( HelpAct.class ) );

		}

	/*
		private OnClickListener getBasicLauncherListener( final Class toLaunch )
		{
			OnClickListener listener = new OnClickListener()
			{
				@Override
				public void onClick( View v )
				{
					Context c = getApplicationContext();
					Intent intent = new Intent( c, toLaunch );
					MenuAct.this.startActivity( intent );

				}
			};

			return listener;
		}
	*/
	@Override
	public void onStart()
	{
		Utils.Log( "Menu onStart", this );
		super.onStart();
	}

	@Override
	public void onResume()
	{
		Utils.Log( "Menu onResume", this );
		super.onResume();
	}

	@Override
	public void onPause()
	{
		Utils.Log( "Menu onPause", this );
		super.onPause();
	}

	@Override
	public void onStop()
	{
		Utils.Log( "Menu onStop", this );
		super.onStop();
	}

	@Override
	public void onDestroy()
	{
		Utils.Log( "Menu onDestroy", this );
		super.onDestroy();
	}

}